package com.lsq.tucao.express.controller;

import com.lsq.tucao.express.bean.po.HeartDetail;
import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.HeartExpressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/heart")
public class HeartExpressController {

    @Autowired
    private HeartExpressService heartExpressService;

    /**
     * 发布心灵鸡汤
     * @param heartDetail 鸡汤实体类
     * @return
     */
    @PostMapping
    public JsonResult addHeart(@RequestBody HeartDetail heartDetail){
        log.debug("heartDetail:{}",heartDetail);

        return heartExpressService.addHeart(heartDetail);
    }

//    /**
//     * @author lsq
//     * @description 给鸡汤点赞
//     * @param heartId 点赞的鸡汤Id
//     * @return com.lsq.tucao.express.response.JsonResult
//     * @create 2021/4/20 22:16
//     */
//    @PutMapping("i-like")
//    public JsonResult likeTucao(@RequestParam Long heartId){
//        log.debug("heartId:{}",heartId);
//
//        return heartExpressService.likeHeart(heartId);
//    }

    /**
     * 分页展示心灵鸡汤
     * @param current 页码
     * @param size 每页条数
     * @param verify 是否审核；0表示未审核，1表示审核通过，2表示审核未通过
     * @param getVerified 获取已审核的数据
     * @return
     */
    @GetMapping("/page")
    public JsonResult pageHeart(@RequestParam(required = false,defaultValue = "1") Integer current,
                                @RequestParam(required = false,defaultValue = "10") Integer size,
                                @RequestParam(required = false) Integer verify,
                                @RequestParam(required = false,defaultValue = "false") Boolean getVerified){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("verify:{}",verify);
        log.debug("getVerified:{}",getVerified);

        return heartExpressService.pageHeart(current,size,verify,getVerified);
    }

    /**
     * @author lsq
     * @description 根据id查询心灵鸡汤数据
     * @param heartId id
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/16 11:59
     */
    @GetMapping("/one")
    public JsonResult getHeartById(@RequestParam Long heartId){
        log.debug("heartId:{}",heartId);
        return heartExpressService.getHeartById(heartId);
    }

    /**
     * @author lsq
     * @description 审核心灵鸡汤数据
     * @param heartId id
     * @param verify true：审核通过；false：审核未通过
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/16 12:34
     */
    @PutMapping("/verify")
    public JsonResult verifyHeart(@RequestParam Long heartId,
                                  @RequestParam Boolean verify){
        log.debug("heartId:{}",heartId);
        log.debug("verify:{}",verify);

        return heartExpressService.verifyHeart(heartId,verify);
    }

    /**
     * @author htt
     * @description 根据鸡汤内容模糊查询
     * @param current 页码
     * @param size 每页条数
     * @param heartContent 输入的鸡汤内容
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 18:27
     */
    @GetMapping("/search-by-content")
    public JsonResult searchHeartBy(@RequestParam(required = false,defaultValue = "1") Integer current,
                                    @RequestParam(required = false,defaultValue = "10") Integer size,
                                    @RequestParam String heartContent){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("heartContent:{}",heartContent);

        return heartExpressService.searchHeartByContent(current,size,heartContent);
    }

    /**
     * @author lsq
     * @description 根据用户查询鸡汤
     * @param current 页码
     * @param size 每页条数
     * @param username 用户名
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 19:18
     */
    @GetMapping("/search-by-username")
    public JsonResult searchHeartByUsername(@RequestParam(required = false,defaultValue = "1") Integer current,
                                        @RequestParam(required = false,defaultValue = "10") Integer size,
                                        @RequestParam String username){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("username:{}",username);

        return heartExpressService.searchHeartByUsername(current,size,username);
    }

    /**
     * @author lsq
     * @description 对鸡汤数据进行排序
     * @param current 页码
     * @param size 每页条数
     * @param sortBy 排序依据
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 19:20
     */
    @GetMapping("/sort")
    public JsonResult sortHeartBy(@RequestParam(required = false,defaultValue = "1") Integer current,
                                  @RequestParam(required = false,defaultValue = "10") Integer size,
                                  @RequestParam String sortBy){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("sortBy:{}",sortBy);

        return  heartExpressService.sortHeartBy(current,size,sortBy);
    }

}
